﻿using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace ClassLibrary1.Model
{

    public class Graph
    {
        // 图结构的核心属性 ， 描述图中所有的点，以及该点的所在的边
        public Dictionary<Point3d, List<Tuple<Point3d, Double>>> AdjacencyList;

        public Graph(List<Line> lines)
        {
            AdjacencyList = new();
            foreach (Line line in lines)
            {
                Point3d ptStart = line.StartPoint;
                Point3d ptEnd = line.EndPoint;

                double distance = ptStart.DistanceTo(ptEnd);

                if (!AdjacencyList.ContainsKey(ptStart))
                {
                    AdjacencyList[ptStart] = new List<Tuple<Point3d, double>>();
                }
                if (!AdjacencyList.ContainsKey(ptEnd))
                {
                    AdjacencyList[ptEnd] = new List<Tuple<Point3d, double>>();
                }
                AdjacencyList[ptStart].Add(new Tuple<Point3d, double>(ptEnd, distance));
                AdjacencyList[ptEnd].Add(new Tuple<Point3d, double>(ptStart, distance));

            }
        }
    }
}
